package stack_and_queue;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author: Zhenzhou Liu
 * @create: 2025-01-10
 * @Description:
 */
public class ReverseStackWithRecursive {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < n; i++) {
            stack.push(scanner.nextInt());
        }
        reverse(stack);
        for (int i = 0; i < n; i++) {
            if (i > 0)
                System.out.print(' ');
            System.out.print(stack.pop());
        }
    }

    private static void reverse(Stack<Integer> stack) {
        if (stack.empty())
            return;
        int x = getAngRemoveLastElement(stack);
        reverse(stack);
        stack.push(x);
    }

    private static int getAngRemoveLastElement(Stack<Integer> stack) {
        int x = stack.pop();
        if (stack.empty())
            return x;
        else {
            int last = getAngRemoveLastElement(stack);
            stack.push(x);
            return last;
        }
    }

}
